﻿CREATE PROCEDURE [dbo].[ew_sp_parse_version]
    @vc_version VARCHAR(1024),
    @i_major    INT OUTPUT,
    @i_minor    INT OUTPUT,
    @i_build    INT OUTPUT,
    @i_revision INT OUTPUT
AS
    SET @i_major    = NULL
    SET @i_minor    = NULL
    SET @i_build    = NULL
    SET @i_revision = NULL

    WHILE @i_revision IS NULL
    BEGIN
        DECLARE @vc_text VARCHAR(1024),
                @i_index INT,
                @i_value INT

        SET @i_index = CHARINDEX('.', @vc_version)

        IF @i_index > 0
            SET @vc_text = LEFT(@vc_version, @i_index - 1)
        ELSE
            SET @vc_text = @vc_version

        SET @i_value = CONVERT(INT, @vc_text)

        IF @i_major IS NULL
            SET @i_major = @i_value
        ELSE IF @i_minor IS NULL
            SET @i_minor = @i_value
        ELSE IF @i_build IS NULL
            SET @i_build = @i_value
        ELSE IF @i_revision IS NULL
            SET @i_revision = @i_value

        SET @vc_version = RIGHT(@vc_version, LEN(@vc_version) - @i_index)
    END
RETURN 0
